package com.lingjtx.order.controller;

import com.alibaba.fastjson2.JSONObject;
import com.lingjtx.common.core.ResponseResult;
import com.lingjtx.common.core.annotation.IgnoreLogin;
import com.lingjtx.common.thread.core.PoolNameConst;
import com.lingjtx.common.thread.core.ThreadPoolManager;
import com.lingjtx.order.service.NotifyService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/notify")
@RequiredArgsConstructor
public class NotifyController {

    private final ThreadPoolManager threadPoolManager;
    private final NotifyService notifyService;

    @IgnoreLogin
    @PostMapping("/weixin")
    public ResponseResult<Void> wepayNotify(@RequestBody JSONObject model, HttpServletRequest request) {
//        String serial = request.getHeader("Wechatpay-Serial");
        String signature = request.getHeader("Wechatpay-Signature");
        String timestamp = request.getHeader("Wechatpay-Timestamp");
        String nonce = request.getHeader("Wechatpay-Nonce");
        threadPoolManager.execute(PoolNameConst.POOL_DEFAULT, () -> notifyService.wepayNotify(model.toString(), signature, timestamp, nonce));
        return ResponseResult.createBySuccess();
    }
}
